import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/login")
public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String role = request.getParameter("role");
        boolean authenticated = authenticate(username, password, role);

        if (authenticated) {
            switch(role) {
                case "teacher":
                    response.sendRedirect("teacher.jsp");
                    break;
                case "student":
                    response.sendRedirect("student.jsp");
                    break;
                case "admin":
                    response.sendRedirect("admin.jsp");
                    break;
            }
        } else {
            request.setAttribute("error", "Invalid username or password");
            request.getRequestDispatcher("login.html").forward(request, response);
        }
    }

    private boolean authenticate(String username, String password, String role) {

        return true;
    }
}
